/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
// Function.cpp: implementation of the CFunction class.
//
//////////////////////////////////////////////////////////////////////
#include "ssi_data.h"
#include "ssi_variable.h"
#include "ssi_function.h"
#include "ssi_function.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

unsigned int CFunction::StackAddr = 0;

CFunction::CFunction()
{
  Stat = STAT_OK;
  NumParams = 0;
}

CFunction::~CFunction()
{

}

CFunction::CFunction(const String& inName)
{
  NumParams = 0;
  Name = inName;
}

CStatus CFunction::AddParam(CVariable &inVar)
{
	if(inVar.GetWorkingNode()){
		if(!Params.push(inVar.GetWorkingVariable())){
			Stat.Set(sERROR, String("Data could not be sent to function"));
			return Stat;
		}
	}else if(!Params.push(inVar)){
   Stat.Set(sERROR, String("Data could not be sent to function"));
   return Stat;
  }
  NumParams++;
  return STAT_OK;
}

void CFunction::SetReturn(CVariable &inVar)
{
  Return = inVar;
}

CVariable CFunction::GetReturn()
{
  return Return;
}

CFunction& CFunction::operator =(CFunction &Other)
{
  Name = Other.Name;
  Params = Other.Params;
  Return = Other.Return;
  Stat = Other.Stat;
  NumParams = Other.NumParams;
  StackAddr = Other.StackAddr;
  return *this;
}

SSI_INT64 CFunction::GetNumParams()
{
  return NumParams;
}

CVariable CFunction::GetVariable(SSI_INT64 Index)
{
  ParamNode* aVar = Params[Index];
  CVariable Ret;
  if(aVar)
  {
    aVar->Get(Ret);
    return Ret;
  }
  //CVariable aVar = Params[Index];
  return CVariable();
}

//CData CFunction::GetVariableData(SSI_INT64 Index)
//{
//  CVariable Temp = GetVariable;
//

//}

CStatus CFunction::GetStatus()
{
  return Stat;
}

void CFunction::SetStatus(CStatus In)
{
  Stat = In;
}

void CFunction::SetStack(unsigned int NewAddr)
{
  StackAddr = NewAddr;
}

unsigned int CFunction::GetStack(void)
{
  return StackAddr;
}




